/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.lucava.boatskeeper.server.handler.boat;

import net.customware.gwt.dispatch.server.ActionHandler;
import net.customware.gwt.dispatch.server.ExecutionContext;
import net.customware.gwt.dispatch.shared.ActionException;
import org.lucava.boatskeeper.server.MockBoatDao;
import org.lucava.boatskeeper.shared.rpc.boat.DeleteBoats;
import org.lucava.boatskeeper.shared.rpc.boat.DeleteBoatsResult;

/**
 *
 * @author glenn
 */
public class DeleteBoatsHandler implements ActionHandler<DeleteBoats, DeleteBoatsResult> {

    @Override
    public Class<DeleteBoats> getActionType() {
        return DeleteBoats.class;
    }

    @Override
    public DeleteBoatsResult execute(DeleteBoats a, ExecutionContext ec) throws ActionException {

        for (Integer id : a.getIds()) {
            MockBoatDao.delete(MockBoatDao.get(id));
        }
        DeleteBoatsResult deleteBoatsResult = new DeleteBoatsResult(MockBoatDao.getAll());
        return deleteBoatsResult;
    }

    @Override
    public void rollback(DeleteBoats a, DeleteBoatsResult r, ExecutionContext ec) throws ActionException {
    }
}
